﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Interop;
using NAudio.Wave;

namespace KochamPycze.Analisys
{
    class SoundCapture : IDisposable
    {
        private WaveIn input;
        private byte[] output;
        private int size;

        private void input_DataAvailable(Object sender, WaveInEventArgs args){
            size = args.BytesRecorded;
            output = args.Buffer;
            DataAvailable.Invoke(size,output);
        }

        public SoundCapture()
        {
            input = new WaveIn();
            input.WaveFormat = new WaveFormat(44100, 16, 1);
            input.DataAvailable += new EventHandler<WaveInEventArgs>(input_DataAvailable);
        }

        public WaveFormat WaveFormat { get { return input.WaveFormat; } }

        public event Action<int, byte[]> DataAvailable;


        public void Start()
        {
            input.StartRecording();
        }

        public virtual void Dispose()
        {
            input.StopRecording();
            input.Dispose();
        }
    }
}
